<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://www.springframework.org/security/tags"
	prefix="security"%>

<style type="text/css">
<!--
.STYLE1 {
	font-size: 12px
}

.STYLE3 {
	color: #707070;
	font-size: 12px;
}

.STYLE5 {
	color: #0a6e0c;
	font-size: 12px;
}

body {
	margin-top: 0px;
	margin-bottom: 0px;
}

.STYLE7 {
	font-size: 12
}
-->
</style>
<script language="javascript">
	function checkForm() {
		var courseId = document.getElementById("courseId").value;
		var courseName = document.getElementById("courseName").value;
		var hours = document.getElementById("hours").value;
		var credit = document.getElementById("credit").value;
		var courseType = document.getElementById("courseType").value;
		var deptId = document.getElementById("deptId").value;
		var majorId = document.getElementById("majorId").value;

		if (courseId == null || courseId == "") {
			alert("请输入课程编号！");
			return false;
		}
		if (courseName == null || courseName == "") {
			alert("请输入课程名称！");
			return false;
		}
		if (hours == 0 || hours == "") {
			alert("请输入课程学时数！");
			return false;
		}
		if (credit == 0 || credit == "") {
			alert("请输入课程学分！");
			return false;
		}
		if (courseType == 0) {
			alert("请选择所属课程类型！");
			return false;
		}
		if(courseType ==1){
			if (deptId == 0) {
			alert("请选择所属院系！");
			return false;
			}
			if (majorId == 0) {
			alert("请选择所属专业！");
			return false;
			}
		}
		
	}

	function hideDeptAndMajor() {
		var courseType = document.getElementById("courseType").value;
		if (courseType == 2) {
			var deptDiv = document.getElementById("dept");
			deptDiv.style.display = "none";
			var majorDiv =document.getElementById("major");
			majorDiv.style.display= "none";
		}
		if(courseType ==1){
			var deptDiv = document.getElementById("dept");
			deptDiv.style.display = "block";
			var majorDiv =document.getElementById("major");
			majorDiv.style.display= "block";
		}
	}
</script>
<script language="javascript">
	var req;

	function init() {
		if (window.XMLHttpRequest) {
			req = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}

	//根据院系ID查询DropChangeAJAXAction，获得该院系的专业列表
	function changeDropOfMajor() {
		init();

		var url = "dropChangeAJAX.do?method=dropChangeOfMajor&deptId="
				+ escape(document.forms[0].deptId.options[document.forms[0].deptId.selectedIndex].value);

		req.open("get", url, true);
		req.onreadystatechange = callback;
		req.send(null);
	}

	function callback() {
		if (4 == req.readyState) {
			if (200 == req.status) {
				eval(req.responseText);
			}
		}
	}
</script>

<html:form action="course.do?method=save" method="post" onsubmit="return checkForm();">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr>
			<td height="30">
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td>&nbsp;</td>
					<td style="padding-right: 10px;">
					<div align="right"></div>
					</td>
				</tr>
			</table>
			</td>
		</tr>
		<tr>
			<td>
			<table width="100%" border="0" cellpadding="0" cellspacing="1"
				bgcolor="#c9c9c9">
				<tr>
					<td width="70%" height="22" bgcolor="#FFFFFF"><strong><span
						class="STYLE1">增加课程</span></strong>
											</td>

				</tr>
				<tr>
					<td bgcolor="#FFFFFF">

					<table width="700" border="0" align="center" cellpadding="0"
						cellspacing="0">
						<tr>
							<td width="164" align="right">课程编号：</td>
							<td width="536"><html:text property="courseId" /><font
								color="red">${courseIdError }</font>
								<font color="red">${courseIdRequire}</font>	
								<font color="red">${courseIdLength}</font>
								</td>
						</tr>
						<tr>
							<td align="right">课程名称：</td>
							<td><html:text property="courseName" /><font color="red">${courseNameError
							}</font></td>
						</tr>
						<tr>
							<td align="right">学时数：</td>
							<td><html:text property="hours" /><font color="red">${courseHoursError
							}</font></td>
						</tr>
						<tr>
							<td align="right">学分：</td>
							<td><html:text property="credit" /><font color="red">${courseCreditError
							}</font></td>
						</tr>
						<tr>
							<td align="right">课程类型：</td>
							<td>
								
								<html:select property="courseType" onchange="hideDeptAndMajor();">
									<html:option value="0">请选择</html:option>
									<html:option value="1">专业课</html:option>
									<security:authorize ifAnyGranted="ROLE_ADMIN">
										<html:option value="2">公共课</html:option>
									</security:authorize>
								</html:select><font color="red">${courseTypeError }</font><font color="red">${deptAndMajorError}</font>
							</td>
						</tr>

						<security:authorize ifAnyGranted="ROLE_DEPT_ADMIN">
							<tr>
								<td align="right">所属院系：</td>
								<td>
								<div id="dept"><html:select property="deptId">
									<html:option value="0">请选择</html:option>
									<html:option value="${dept.id}">${dept.deptName}</html:option>
								</html:select><font color="red">${courseDeptIdError }</font></div>
								</td>
							</tr>
							<tr>
								<td align="right">所属专业：</td>
								<td>
								<div id="major"><html:select property="majorId">
									<html:option value="0">请选择</html:option>
									<c:if test="${!empty majorList}">
										<html:optionsCollection name="majorList" label="majorName"
											value="id" />
									</c:if>
								</html:select><font color="red">${courseMajorIdError }</font></div>
								</td>

							</tr>
						</security:authorize>

						<security:authorize ifAnyGranted="ROLE_ADMIN">
							<tr>
								<td align="right">所属院系：</td>
								<td>
								<div id="dept"><html:select property="deptId"
									onchange="changeDropOfMajor()">
									<html:option value="0">请选择</html:option>
									<c:if test="${!empty deptList}">
										<html:optionsCollection name="deptList" label="deptName"
											value="id" />
									</c:if>
								</html:select><font color="red">${courseDeptIdError }</font></div>
								</td>
							</tr>
							<tr>
								<td align="right">所属专业：</td>
								<td>
								<div id="major"><html:select property="majorId">
									<html:option value="0">请选择</html:option>
									<c:if test="${!empty majorList}">
										<html:optionsCollection name="majorList" label="majorName"
											value="id" />
									</c:if>
								</html:select><font color="red">${courseMajorIdError }</font></div>
								</td>
							</tr>
						</security:authorize>

						<tr>
							<td align="center">&nbsp;</td>
							<td>&nbsp;</td>
						</tr>
						<tr>
							<td align="center">&nbsp;</td>
							<td><html:submit value="确认增加" /> &nbsp;&nbsp;&nbsp; <html:reset
								value="取 消" /></td>
						</tr>
					</table>
					</td>
				</tr>
			</table>
			</td>
		</tr>
		<tr>
			<td height="35">&nbsp;</td>
		</tr>
	</table>
</html:form>